﻿using System.Data.Linq;
using System.Linq;
using TSharp.Core.Repository.EntityFramework;
using TSharp.Core.Repository;
[assembly: TSharp.Core.Osgi.RegService(typeof(IUnitOfWorkConvertor), typeof(EntityFrameworkUnitOfWorkConvertor))]
namespace TSharp.Core.Repository.EntityFramework
{
    /// <summary>
    /// Helper class to convert Entity Framework DbContext to various data providers.
    /// </summary>
    public class EntityFrameworkUnitOfWorkConvertor : IUnitOfWorkConvertor
    {
        /// <summary>
        /// Gets <see cref="IQueryable"/> from <see cref="DataContext"/> wrapped
        /// in the given <see>
        ///                  <cref>LinqToSqlUnitOfWork</cref>
        ///              </see>
        ///     instance.
        /// </summary>
        public IQueryable<TEntity> ToQueryable<TEntity>(IUnitOfWork unitOfWork) where TEntity : class
        {
            var entityFrameworkUnitOfWork = unitOfWork as EntityFrameworkUnitOfWork;
            if (entityFrameworkUnitOfWork != null)
                return entityFrameworkUnitOfWork.ToQueryable<TEntity>();
            throw new System.ArgumentNullException("unitOfWork");
        }
    }
}
